///区域、区域类型和门牌号的联力查询
var curr_region_type = "";
var curr_region_name = "";

function iniREGIONTYPE() {
	$('#input_REGION_TYPE').combobox({
		valueField: 'NAME',
		textField: 'NAME',
		panelHeight: 'auto',
		method: 'get',
		mode: 'remote',
		url: RemoteLinkAddress + '/market/regiontype/listall.do',
		onSelect: function(record) {
			RegionData(record.ID, record.NAME);
		}
	});
}

function HouseNumberData(name, type) {
	var _url = RemoteLinkAddress + '/market/boost/listall.do?REGION_TYPE=' + type + '&REGION_NAME=' + name;
	console.log(_url);
	$('#input_HOUSE_NUMBER').combobox({
		valueField: 'HOUSE_NUMBER',
		textField: 'HOUSE_NUMBER',
		panelHeight: 'auto',
		method: 'get',
		mode: 'remote',
		url: _url,
		onSelect: function(record) {
			$('#input_BOOST_ID').textbox('setValue', record.ID)
		}
	});
}

function RegionData(id, region_type_name) {
	var _url = RemoteLinkAddress + "/market/region/listall.do?TYPE_ID=" + id;
	$.ajax({
		type: "get",
		url: _url,
		dataType: "json",
		success: function(result) {
			if(result != null) {
				$('#input_REGION_NAME').combobox({
					valueField: 'NAME',
					textField: 'NAME',
					data: result,
					panelHeight: 'auto',
					onSelect: function(record) {
						HouseNumberData(record.NAME, region_type_name);
					}
				});
			}
		},
		error: function(xhr, status, error) {
			$.messager.alert("错误", "请求失败!");
		}
	});
}

//租户姓名模糊查询
function createTenantCombobox() {
	$('#input_TENANT_NAME').combobox({
		valueField: 'TENANT_NAME',
		textField: 'TENANT_NAME',
		panelHeight: 'auto',
		mode: 'remote',
		method: 'get',
		onChange: function(newValue, oldValue) {
			if(newValue != "" && newValue != undefined) {
				var url = RemoteLinkAddress + "/market/tenant/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
				$(this).combobox("reload", url);
			}
		},
		onSelect: function(record) {
			$('#input_TENANT_ID').textbox("setValue", record.ID);
		}
	});
}

function editDataGridRefresh(editMethod, row, updateData, isRecord) {
	if(editMethod === "end") {
		if(currid != AddFlag) {
			if(isRecord == false || isRecord == undefined) //即修改的情况
			{
				for(var i = 0; i < updateData.rows.length; i++) {
					if(updateData.rows[i].ID == row.ID) {
						var obj = updateData.rows[i];
						for(var s in obj) {
							if(obj[s] != row[s]) {
								obj[s] = row[s];
							}
						}
					}
				}
			} else {
				var len = updateData.rows.length;
				updateData.rows[len] = row;
				updateData.rows[len].ORDER_ID = currid;
			}
		}
	} else if(editMethod === "destory") {
		if(currid != AddFlag) {
			for(var i = 0; i < updateData.rows.length; i++) {
				if(updateData.rows[i].ID == row.ID) {
					updateData.rows[i].ORDER_ID = ""; //直接替换
				}
			}
		}
	}
}